<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");	
	String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : ""; 
%>
<!DOCTYPE HTML>
<html>
  <head>
    <%@include file="../common.jsp"%>
    <title>添加资料</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">  
<!-- 	<link rel="stylesheet" type="text/css" href="resources/css/common.css">  -->
	<script type="text/javascript" src="resources/js/file/add_file.js"></script>  
	<script type="text/javascript" src="resources/js/cookie.js"></script>
	
	<!--kindEditor -->
    <link rel="stylesheet" href="resources/js/kindeditor/themes/default/default.css" />
	<link rel="stylesheet" href="resources/js/kindeditor/plugins/code/prettify.css" />
	<script charset="utf-8" src="resources/js/kindeditor/kindeditor.js"></script>
	<script charset="utf-8" src="resources/js/kindeditor/lang/zh_CN.js"></script>
	<script charset="utf-8" src="resources/js/kindeditor/plugins/code/prettify.js"></script> 
	
<!-- 	<script type="text/javascript" src="resources/js/jquery.tagbox.js"></script>  
	<link rel="stylesheet" type="text/css" href="resources/css/jquery.tagbox.css"> -->
	
	
	<!-- 断点上传 -->
	<link rel="stylesheet" href="resources/css/webuploader.css" />
    <link rel="stylesheet" href="resources/css/bootstrap/bootstrap.css" />
	<script src="resources/js/md5.js" type="text/javascript" charset="utf-8"></script>
	<script src="resources/js/webuploader.js" type="text/javascript" charset="utf-8"></script>
  	<script src="resources/js/fileUpload.js" type="text/javascript" charset="utf-8"></script>

	<script src="resources/js/tag/jquery.tagsinput.js"></script>
	<link href="resources/js/tag/jquery.tagsinput.css" rel="stylesheet" />	
		
	<script>
 		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="content1"]', {
				cssPath : 'resources/js/kindeditor/plugins/code/prettify.css',
				uploadJson : 'resources/js/kindeditor/jsp/upload_json.jsp',
				fileManagerJson : 'resources/js/kindeditor/jsp/file_manager_json.jsp',
				allowFileManager : true,
/* 				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
						document.forms['example'].submit();
					});
				}  */
				
				afterBlur: function(){
					this.sync();
				}
			});
			prettyPrint();
		});
		
var cook = new cookie();//实例化cookie

/** ***********添加分类********************* */
	 function addCategory(object) {
			// 一级分类选择
			var $second = object.find("[name=second]"), 
			$top = object.find("[name=top]");
			$detail = object.find("[name=detail]"), 
			$content = object.find("[name=content]"), 
			$projectMode = object.find("[name=project_mode]"), 

			tcId = 	cook.getCookie("tcId");
			scId = 	cook.getCookie("scId");
			detailId =  cook.getCookie("detail");
			contentId = cook.getCookie("content");
			project_modeId = cook.getCookie("project_mode");
			if (tcId == 1) {
				$content.hide();
				$projectMode.hide();
			}
			$.get("category/getTopCategoryOfDatabase", function(data) {
				$.each(data.data, function(i, obj) {
					if(obj.tcId== tcId){
						$top.append("<option value='" + obj.tcId + "' selected>" + obj.tcName+ "</option>");
					}else{
						$top.append("<option value='" + obj.tcId + "'>" + obj.tcName+ "</option>");
					}
				});
			}, "json");
		if(detailId.length !=0){
			//做缓存数据用开始
			$.ajax({ // 此处用同步处理，避免出现val()比reload早的问题
						url : serverURL + "category/getSecondaryCategory?"+ "tcId=" + tcId,
						type : "get",
						async : false,
						success : function(data) {
							if (data.code == 0) {
								var html = "";
								$.each(data.data, function(i, k) {
									if (k.scId == scId) {
										html += "<option value='" + k.scId+ "' selected>" + k.scName	+ "</option>";
									} else {
										html += "<option value='" + k.scId + "'>"+ k.scName + "</option>";
									}
								});
								$second.append(html);
							} else if (data.code != -1) {
								alert("一二级分类数据加载失败");
							}
						}
					});
					
			$.ajax({
				url : serverURL + "category/getDetailCategory?" + "scId=" + scId+ "&dcTypeId=0",
				type : "get",
				async : false,
				success : function(data) {
					if (data.code == 0) {
						var detail = content = projectMode = "";
						$.each(data.data, function(i, k) {
							if (k.dcType == 1 || k.dcType == 4 || k.dcType == 7) {
								if (k.dcId == detailId) {
									detail += "<option value='" + k.dcId+ "' selected >" + k.dcName+ "</option>";
								} else {
									detail += "<option value='" + k.dcId + "'>"+ k.dcName + "</option>";
								}
							} else if (k.dcType == 2 || k.dcType == 5|| k.dcType == 8) {
								if (k.dcId == contentId ) {
									content += "<option value='" + k.dcId+ "' selected >" + k.dcName+ "</option>";
								} else {
									content += "<option value='" + k.dcId + "'>"+ k.dcName + "</option>";
								}
	
							} else if (k.dcType == 3 || k.dcType == 6|| k.dcType == 9) {
								if (k.dcId == project_modeId) {
									projectMode += "<option value='" + k.dcId+ "' selected >" + k.dcName+ "</option>";
								} else {
									projectMode += "<option value='" + k.dcId+ "'>" + k.dcName + "</option>";
								}
	
							} else if (k.dcType == 0) { // 国内工程资料
								if (k.dcId == detailId) {
									detail += "<option value='" + k.dcId+ "' selected >" + k.dcName+ "</option>";
								} else {
									detail += "<option value='" + k.dcId + "'>"+ k.dcName + "</option>";
								}
							}
						});
						$detail.append(detail);
						$content.append(content);
						$projectMode.append(projectMode);
					} else if (data.code != -1) {
						alert("三级分类数据加载失败");
					}
				}
			});
			//做缓存数据结束
		}			
			
			
			/*--------------修改的一、二、三级二级联动处理----------------*/
		 $top.change(function() {
				districtEdit.clearDetail();
				districtEdit.reloadSecond($(this).val());
				$content.show();
				$projectMode.show();
				if($(this).val() == 1 ){
					$content.hide();
					$projectMode.hide();
				}
			});
	
			$second.change(function() {
				districtEdit.reloadDetail($(this).val());
			});
	
			var districtEdit = {
				clearSecond : function() {
					$second.find("option[value!=0]").remove();
				},
				clearDetail : function() {
					$detail.find("option[value!=0]").remove();
					$content.find("option[value!=0]").remove();
					$projectMode.find("option[value!=0]").remove();
				},
				reloadSecond : function(tcId) {
					districtEdit.clearSecond();
					if (tcId != 0) {
						$.ajax({ // 此处用同步处理，避免出现val()比reload早的问题
							url : serverURL + "category/getSecondaryCategory?"+ "tcId=" + tcId,
							type : "get",
							async : false,
							success : function(data) {
								if (data.code == 0) {
									var html = "";
									$.each(data.data, function(i, k) {
										html += "<option value='" + k.scId +"'>"+ k.scName + "</option>";
									});
									$second.append(html);
								} else if (data.code != -1) {
									alert("二级分类数据加载失败");
								}
							}
						});
					}
				},
				reloadDetail : function(scId) {
					districtEdit.clearDetail();
					if (scId != 0) {
						$.ajax({
							url : serverURL + "category/getDetailCategory?"+ "scId=" + scId+"&dcTypeId=0",
							type : "get",
							async : false,
							success : function(data) {
								if (data.code == 0) {
									$.each(data.data, function(i, k) {
										if(k.dcType == 1 ||k.dcType == 4  |k.dcType == 7 ){
											$detail.append("<option value='" + k.dcId + "'>"+ k.dcName + "</option>");
										}else if (k.dcType == 2 ||k.dcType == 5  |k.dcType == 8){
											$content.append("<option value='" + k.dcId + "'>"+ k.dcName + "</option>");
										}else if (k.dcType == 3 ||k.dcType == 6  |k.dcType == 9){
											$projectMode.append("<option value='" + k.dcId + "'>"+ k.dcName + "</option>");
										}else if (k.dcType == 0 ){ // 国外工程资料
											$detail.append("<option value='" + k.dcId + "'>"+ k.dcName + "</option>");
										}
									});
								} else if (data.code != -1) {
									alert("三级分类数据加载失败");
								}
							}
						});
					}
				}
			};
	}
	</script>
  </head>
  <body>
	<div class="content">
   		<ol class="breadcrumb">
		  <li><a href="file.htm">资料列表</a></li>
		  <li class="active">添加资料</li>
		</ol>
		<!-- 添加 -->
		<div class="modal-body" style="margin-left:50px;">
		<div id="itemFileName" ></div>
			<div style="height:50px;">
				<ul id="theList"></ul>
			</div>
			<div id="uploader">
				<button id="picker" resetValue="0" class="btn btn-primary ">选择文件</button>
			</div>
		</div>
		<div class="modal-content">
			<div class="modal-body">
				<form id="form_add" class="form-horizontal" role="form">
				<input type="hidden" name="url" id="url">
				<input type="hidden" id="fileSize">
				<input type="hidden" name="mold" value="0">
				<div class="form-group">
						  <label class="col-sm-2 control-label required">文件标题</label>
						  <div class="col-sm-4">
						     <input type="text" name="name" placeholder="50字以内,如:建筑设计" class="form-control" data-toggle="tooltip" data-placement="top" title="请输入不多于50个字" >
						  </div>
						  <label class="col-sm-2 control-label required">文件格式</label>
						  <div class="col-sm-4">
							<select class="form-control" name="type" placeholder="选择文件格式" data-toggle="tooltip" data-placement="top" title="请选择文件格式">
								<option value="0" selected="selected">请选择...</option>
							</select> 
						</div>
					  </div>
					  
 					  <div class="form-group">
								<label class="col-md-2 control-label required">一级分类</label>
								<div class='col-md-4'>
									<select class="form-control" name="top" placeholder="选择一级分类"
										data-toggle="tooltip" data-placement="top" title="请选择一级分类">
										<option value="0" selected="selected">请选择...</option>
									</select>
								</div>
								<label class="col-md-2 control-label required">二级分类</label>
								<div class='col-md-4'>
									<select class="form-control" name="second" placeholder="选择二级分类"
										data-toggle="tooltip" data-placement="top" title="请选择二级分类">
										<option value="0" selected="selected">请选择...</option>
									</select>
								</div>
							</div>
							
					  <div class="form-group">
								<label class="col-md-2 control-label">三级分类</label>
								<div class='col-md-3'>
									<select class="form-control" name="detail" id= "major" placeholder="选择专业"
										data-toggle="tooltip" data-placement="top" title="请选择专业">
										<option value="0" selected="selected">请选择类别（专业）...</option>
									</select>
									</div>
									<div class='col-md-3'>
									<select class="form-control" name="content" placeholder="选择内容"
										data-toggle="tooltip" data-placement="top" title="请选择内容">
										<option value="0" selected="selected">请选择内容...</option>
									</select>
									</div>
									<div class='col-md-3'>
									<select class="form-control" name="project_mode" placeholder="选择项目模式"
										data-toggle="tooltip" data-placement="top" title="请选择项目模式">
										<option value="0" selected="selected">请选择项目模式...</option>
									</select>
								</div>
							</div>

				  	  <div class="form-group">
						<label class="col-sm-2 control-label required" >价格</label>
						  <div class="col-sm-4">
							 <input type="text" name="price" placeholder="请输入价格,如11.2"  value="0" class="form-control" data-toggle="tooltip" data-placement="top" title="请输入价格">
						  </div>
						  
						  <label class="col-sm-2 control-label required">浏览的基数</label>
						  	<div class="col-sm-4">
								<input type="text" name="cardinal" placeholder="请输入浏览基数" class="form-control" data-toggle="tooltip" data-placement="top" title="请输入浏览基数"> 
							</div>
					  </div>
					  
 				  	  <div class="form-group">
						<label class="col-sm-2 control-label required" >规划体系</label>
						  <div class="col-sm-4">
							      	<select class="form-control" name="hierId" placeholder="选择规划体系"
										data-toggle="tooltip" data-placement="top" title="请选择规划体系">
										<option value="0" selected="selected">请选择规划体系...</option>
									</select>
						  </div>
						  
						  <label class="col-sm-2 control-label required">等级</label>
						  	<div class="col-sm-4">
							      	<select class="form-control" name="grade" placeholder="选择等级"
										data-toggle="tooltip" data-placement="top" title="请选择等级">
									</select>								
							</div>
					  </div>				  
				  	  <div class="form-group">
						  <label class="col-sm-2 control-label required">标签</label>
						  <div class="col-sm-10">
							<input id="tags" type="text" class="tags" value="" />
						  </div>
					  </div>
					  
				  	  <div class="form-group">
						  <label class="col-sm-2 control-label required">文件简介</label>
						  <div class="col-sm-10">
							<%=htmlData%>
							<!-- <form name="example" method="post" action="file_list.jsp"> -->
								<textarea id ="introduction" name="content1" cols="100" rows="8" style="width:100%;height:200px;"><%=htmlspecialchars(htmlData)%></textarea>
								<br />
								<!--<input type="submit" name="button" value="提交内容" /> (提交快捷键: Ctrl + Enter)
							 </form>	 -->				
						</div>
					  </div>
				</form>
		      </div>
			<div class="modal-footer">
				<button id="btn_confirm_add" type="button" class="btn btn-primary">确定</button>
			</div>
		</div>
	</div>
  </body>
</html>

<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>